package com.cangxuan.manage.service.impl;

import com.cangxuan.manage.bean.Page;
import com.cangxuan.manage.dao.IGoodsDao;
import com.cangxuan.manage.dao.ISeriesDao;
import com.cangxuan.manage.entity.Series;
import com.cangxuan.manage.entity.UserAmountRecord;
import com.cangxuan.manage.exception.ServiceException;
import com.cangxuan.manage.service.ISeriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ISeriesServiceImpl implements ISeriesService {
    ISeriesDao iSeriesDao;
    IGoodsDao iGoodsDao;
    @Autowired
    public void setiGoodsDao(IGoodsDao iGoodsDao) {
        this.iGoodsDao = iGoodsDao;
    }

    @Autowired
    public void setiSeriesDao(ISeriesDao iSeriesDao) {
        this.iSeriesDao = iSeriesDao;
    }


    @Override
    public List<Series> list() {
        return iSeriesDao.list();
    }



    @Override
    public boolean saveSeries(Series series) {
         return series.getId() == 0 ? iSeriesDao.insert(series) > 0 : iSeriesDao.update(series) > 0;
    }

    @Override
    public boolean remove(int id) {
        if(iGoodsDao.selectCountBySeriesId(id) > 0){
            throw new ServiceException(402, "已经存在该系列藏品，暂无法删除");
        }
        if (iSeriesDao.delete(id) == 0) {
            throw new ServiceException(402, "删除失败，ID不存在");
        }

        return true;
    }
}
